<?php
/**
 * 服务调用工具类
 * 
 * @author Kevin
 * @since May 13, 2015 7:09:58 PM
 * @version 2.0
 * @copyright
 *
 */
class LibInvokeWrapper {
    /**
     * 服务组名
     *
     * @var sting
     */
    private $groupName = '';
    /**
     * 服务名
     *
     * @var sting
     */
    private $serviceName = '';
    /**
     * 服务版本
     *
     * @var sting
     */
    private $serviceVersion = '';
    
    /**
     * 构造函数
     *
     * @param sting $serviceName            
     * @param string $userClient            
     * @param string $clientVersion            
     * @return boolean
     * @since May 13, 2015 7:20:00 PM
     * @access
     *
     */
    public function __construct() {
    }
    /**
     * 调用服务
     *
     * @param unknown $request_params            
     * @return multitype:string number
     * @since May 14, 2015 4:55:52 PM
     * @access
     *
     */
    public function invokeService($request_params) {
        $groupName = $request_params ['group'];
        $serviceName = $request_params ['service'];
        $serviceVersion = $request_params ['version'];
        $traceId = $request_params ['trace_id'];
        $traceSpanId = 'front#' . $serviceName . '#' . $serviceVersion;
        $request = array (
                'group' => $groupName,
                'service' => $serviceName,
                'version' => $serviceVersion,
                'trace_id' => $traceId,
                'trace_span_id' => $traceSpanId,
                'data' => $request_params 
        );
        LibSOATrace::soaDebug ( $request, $groupName . ':' . $serviceName . ':' . $serviceVersion );
        $req_msg = json_encode ( $request );
        $response = invoke_service ( $groupName, $serviceName, $serviceVersion, $req_msg );
        if (! empty ( $response )) {
            $response = json_decode ( $response, TRUE );
        } else {
            $response = array (
                    'statusCode' => 1,
                    'statusDesc' => 'server side no return data' 
            );
        }
        return $response;
    }
}
?>